package com.myfum.mobile.tetris.data.shapes
{
	import com.myfum.mobile.tetris.data.cubes.CubeData;
	import com.myfum.mobile.tetris.data.cubes.DropingCubeData;
	import com.myfum.mobile.tetris.interfaces.IShape;
	import com.myfum.mobile.tetris.interfaces.ISkinItem;
	
	import flash.display.BitmapData;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	public class ShapeData implements IShape
	{
		private var _cubes:Vector.<DropingCubeData>;
		private var _skin:BitmapData;
		
		public function ShapeData()
		{
			
		}
		
		public function rotate():void{
			throw new Error("this function must be override by child class");
		}
		
		public function undoRotate():void{
			throw new Error("this function must be override by child class");
		}
		
		public function get cubes():Vector.<DropingCubeData>{
			return _cubes;
		}
		
		public function set cubes(value:Vector.<DropingCubeData>):void{
			_cubes = value;
		}
		
		public function get skin():BitmapData{
			return _skin;
		}
		
		public function set skin(value:BitmapData):void{
			_skin = value;
		}
		
		public function stepLeft():void{
			for each(var c:CubeData in cubes){
				c.x -= 1;
			}
		}
		
		public function stepRight():void{
			for each(var c:CubeData in cubes){
				c.x += 1;
			}
		}
		
		public function stepDown():void{
			for each(var c:CubeData in cubes){
				c.y += 1;
			}
		}
		
		public function stepUp():void{
			for each(var c:CubeData in cubes){
				c.y -= 1;
			}
		}
		
		public function clone():ISkinItem{
			var refer:Class = getDefinitionByName(getQualifiedClassName(this)) as Class;
			var vector:Vector.<DropingCubeData> = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<cubes.length;i++){
				vector.push(cubes[i].clone() as DropingCubeData);
			}
			var s:IShape = new refer() as IShape;
			s.cubes = vector;
			return s;
		}
		
		public function dispose():void{
			
		}
	}
}